package com.controller.base;

import com.common.ErrorCodeEnum;
import com.common.anntation.Log;
import com.common.emums.BusinessType;
import com.common.exception.BusinessException;
import com.common.utils.EntityConversionUtil;
import com.github.pagehelper.PageInfo;
import com.model.base.PageResult;
import com.model.base.Result;
import com.model.domain.base.GetBaseServiceStationInfoDO;
import com.model.dto.base.serviceStation.GetStationListDTO;
import com.model.dto.base.serviceStation.UpdateConfirmStatusDTO;
import com.model.pojo.base.BaseServiceStationInfo;
import com.model.vo.base.serviceStation.getStationList.GetStationListVO;
import com.service.base.BaseServiceStationInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * TODO
 *
 * @Description
 * @Author tm
 * @Date 2023-09-09 15:43
 **/
@Api(tags = {"维修服务站管理"})
@Slf4j
@RestController
@RequestMapping("/v1/base/serviceStation")
@RequiredArgsConstructor
public class ServiceStationInfoController {
    private final BaseServiceStationInfoService baseServiceStationInfoService;
    @Log(title = "维修服务站管理-站点列表", businessType = BusinessType.INSERT)
    @ApiOperation(value = "站点列表")
    @PostMapping("/getStationList")
    public Result<PageResult<List<GetStationListVO>>> getStationList(@RequestBody @Valid GetStationListDTO dto){
        List<GetStationListVO> voList = new ArrayList<>();
        GetBaseServiceStationInfoDO getBaseServiceStationInfoDO = EntityConversionUtil.copy(dto, GetBaseServiceStationInfoDO.class);
        List<BaseServiceStationInfo> list = baseServiceStationInfoService.getPageList(getBaseServiceStationInfoDO);
        voList = EntityConversionUtil.copyList(list,GetStationListVO.class);
        PageInfo<BaseServiceStationInfo> pageInfo = new PageInfo<>(list);
        PageResult<List<GetStationListVO>> build = PageResult.<List<GetStationListVO>>builder().result(voList).pageInfo(pageInfo).build();
        return Result.suc(build);
    }

    @ApiOperation(value = "修改确认状态")
    @Log(title = "修改确认状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateConfirmStatus")
    public Result<Objects> updateConfirmStatus(@RequestBody @Valid UpdateConfirmStatusDTO dto) {
        BaseServiceStationInfo baseServiceStationInfo = new BaseServiceStationInfo();
        baseServiceStationInfo.setStationId(dto.getStationId());
        baseServiceStationInfo.setConfirmStatus(dto.getConfirmStatus());
        baseServiceStationInfoService.update(baseServiceStationInfo);
        return Result.suc();
    }

}
